//
//  ViewController.swift
//  Fancyswap
//
//  Created by Jonathan Muschalle on 2015-02-26.
//  Copyright (c) 2015 Jonathan Muschalle. All rights reserved.
//

import UIKit

class MainController: UIViewController {

    @IBOutlet weak var btn_signout: UIButton!
    @IBOutlet weak var btn_signin: UIButton!
    
    override func viewDidLoad() {
    
        self.btn_signin_signout()
        super.viewDidLoad()
        
        // Do any additional setup after loading the view, typically from a nib.
    }

    func btn_signin_signout(){
        
        if(FancyTools.isLogged()){
            self.btn_signin.hidden  = true
            self.btn_signout.hidden = false
        }
        else{
            self.btn_signin.hidden  = false
            self.btn_signout.hidden = true
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func viewDidAppear(animated: Bool) {
        
        self.btn_signin_signout()
    }

    @IBAction func itemAdd(sender: AnyObject) {
        var storyboard = UIStoryboard(name: "ItemAdd", bundle: nil)
        var controller = storyboard.instantiateViewControllerWithIdentifier("itemAdd") as UIViewController
        self.presentViewController(controller, animated: true, completion: nil)
    }
    
    @IBAction func myOrders(sender: AnyObject) {
        var storyboard = UIStoryboard(name: "MyOrders", bundle: nil)
        var controller = storyboard.instantiateViewControllerWithIdentifier("myOrders") as UIViewController
        self.presentViewController(controller, animated: true, completion: nil)
        
    }
    
    @IBAction func myItems(sender: AnyObject) {
        var storyboard = UIStoryboard(name: "MyItems", bundle: nil)
        var controller = storyboard.instantiateViewControllerWithIdentifier("myItems") as UIViewController
        self.presentViewController(controller, animated: true, completion: nil)

    }
    
    @IBAction func itemList(sender: AnyObject) {
        var storyboard = UIStoryboard(name: "ItemList", bundle: nil)
        var controller = storyboard.instantiateViewControllerWithIdentifier("itemList") as UIViewController
        self.presentViewController(controller, animated: true, completion: nil)
    }
   
    @IBAction func signout(sender: AnyObject) {
    
        let auth = Authentification()
        auth.signout()
        self.btn_signin_signout()
    }

    @IBAction func authentication(sender: AnyObject) {
       
       let auth = Authentification()
        
        if(!auth.isLoggedIn()){
            
            var storyboard = UIStoryboard(name: "Authentication", bundle: nil)
            var controller = storyboard.instantiateViewControllerWithIdentifier("authentication") as UIViewController
            self.presentViewController(controller, animated: true, completion: nil)
        }
    }
}

